Skip to content

fix(fields): a failed first load of the line-item grid body recovers on the next mount - #36607

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-36451-grid-field-lazy-retry
Nov 23, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-36451-grid-field-lazy-retry

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #36451

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:控制台记录表单里的明细行表格,第一次加载失败一次后(网络抖动、发版换了文件名),之后再打开表单即可正常显示表格,不用刷新整页。
  • 为什么做:明细行表格按需加载的收尾问题,替所有碰到一次加载失败的表单用户解决「只能刷新页面」。
  • 出错会怎样:只影响明细行表格的加载方式,最坏是加载失败时照旧显示报错;可直接撤回。
  • 要你做什么:无。

What changes

  • GridField / LineItemsField (ui/packages/fields/src/widgets/GridField.ts) no longer render the body through a module-scope React.lazy. A lazy component keeps its first outcome for good, a rejection included, so after one failed load of the body every later mount rethrew that failure until the page was reloaded, although loadGridFieldWidget already forgot the failure. A mount that finds the body still loading now renders GridFieldOnceLoaded: it shows the existing loading placeholder, asks the one loader from an effect (so only a committed mount requests anything; a render React discards before commit cannot loop on a failing chunk), throws a failed load to the nearest error boundary, and the next mount asks again. A mount after the body has loaded still renders it directly in the same render; preloadGridField() is unchanged and never rejects.
  • The grid entry of the form-field loader map (ui/packages/fields/src/index.tsx) resolves to that face instead of a React.lazy around the body, so the registered field:grid widget and getLazyFieldWidget('grid') recover the same way. The face is already in the eager chunk (the entry exports it), so this adds no edge to the body.
  • Patch changeset for @object-ui/fields.

Read first, by risk:

  1. GridField.ts, the GridFieldOnceLoaded function: the effect-driven load, the cleanup guard, the throw of a failed outcome.
  2. index.tsx, the grid entry of the loader map.
  3. GridField.test.tsx, the new after one failed load of the body describe inside the existing lazy-face block.

Tests

Two pins in the existing lazy-face block of GridField.test.tsx: the body module is mocked to fail its first load once and then load normally; the first mount must reach the error boundary and a later mount must render the grid, once for the GridField face and once for getLazyFieldWidget('grid').

Premise, measured on main's code (both pins red)

GridField.ts and index.tsx replaced by their blobs at the branch point e17c2ae1a (hash-verified on disk), then the pins run:

× a later mount of GridField renders the grid once the body is reachable, with no reload
× a later mount of the grid form-field widget renders the grid too
Tests  2 failed | 107 skipped (109)

Both failures: the later mount shows the boundary fallback (grid-load-failed), never line-items. Restored with git checkout HEAD, git diff HEAD empty, HEAD blob hashes matched.

Ablation, one half at a time
  • Face reverted to main, index.tsx fixed: both pins red (the form-field entry reaches the reverted face).
  • index.tsx reverted to main, face fixed: only the form-field pin red (1 failed | 1 passed).

Each leg restored and verified the same way.

Package run at head 66d9f58

pnpm --dir ui exec vitest run --maxWorkers=2 packages/fields/ && pnpm --filter @object-ui/fields run type-check under the shared verify lock:

Test Files  322 passed | 1 skipped (323)
Tests  4893 passed | 7 skipped (4900)
VERDICT command-exit 0

pnpm --dir ui exec vitest run scripts/ (derived gate): 172 files passed, VERDICT command-exit 0. ESLint on the three changed files: 0 errors (warnings pre-existing).

Derived gates at head 66d9f58

dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 39 families; all 39 run, all exit 0, --ran reconciliation: 39 run, 0 NOT-MEASURED, 0 UNRUN. First pass: check:query-options-erasure and check:type-check-debt hit a 300 s harness timeout and check:watch-hint-literal exited 1 once (cause not established); each re-run to completion, exit 0.

Acceptance notes

  • A form drawing a grid field now shows the grid's own loading placeholder (a dashed box of the header's height) while the body loads, where it showed the form's own suspense fallback before.
  • Boundary not measured here: the retry calls import() again for the same chunk URL. Whether a given browser re-fetches a module whose earlier dynamic import failed is engine behaviour; the pins run under vitest/jsdom only.
  • Card step 3, measured with a throwaway test (deleted, not committed): the same edge, a module-scope React.lazy keeping a failed first load until reload, holds for FieldEditWidget's date picker (measured; its datetime picker and rich-text panel are the same construction), richTextDisplay's markdown content (measured), FilterConditionCell (measured), the per-type lazy cache of getLazyFieldWidget and registerField for every other type (measured for date), and ImageField's cropper dialog (same construction, not measured). None is changed here; they are listed for the seat.
  • No README or docs sentence is made false by this change.

Verification

Two-minute check: pnpm --dir ui exec vitest run packages/fields/src/widgets/GridField.test.tsx -t "after one failed load" from the repo root; expect 2 passed.


Generated by Claude Code

…reload

The lazy face replaces a React.lazy whose load failed, so the next mount
asks the loader again; the grid form-field loader now resolves to that face.

Claude-Session: https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD
Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD
Co-authored-by: Claude <noreply@anthropic.com>
…React.lazy

A render React discards before it commits requests nothing, so a failed
load cannot retry in a loop; each later mount asks the loader again.

Claude-Session: https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-steve · session_01ADHkmNmMEXS4EzeVz9RjvD
L1 · 2026-11-23T02:57Z · PR #36607 @ 66d9f58 · card #36451 · area s2-A

席位核对

ACCEPT — one card, one PR, not governed (check-governed-merges.mjs: NOT governed), +127/-20 over four files, Clause-② no, Metadata-protocol none.

  1. Shape. Fixes #36451; no other card bound; files: GridField.ts, the grid entry and one import in ui/packages/fields/src/index.tsx (not the export-list hunk open PR feat(console): preview images, PDF, text and CSV in the page from attachments and file fields #36587 edits), a new describe in GridField.test.tsx, one @object-ui/fields patch changeset.
  2. Premise measured (card step 1). On main, the body chunk failed once and then loaded; a later mount of GridField showed the error boundary, and so did a later mount of getLazyFieldWidget('grid'), because a module-scope React.lazy keeps its rejection.
  3. Code read. LazyGridFieldWidget is gone. A grid mounted before its body arrived renders GridFieldOnceLoaded: each committed mount asks the one loader from an effect (guarded on unmount), shows GridFieldLoading meanwhile, throws a failed load to the nearest boundary, and the loader forgets the failure, so the next mount (boundary reset, reopened form) loads again. A render discarded before commit requests nothing, so a chunk that keeps failing cannot loop. The form-field map's grid entry now resolves to the face already in the chunk (Promise.resolve({ default: GridField })), so the per-type React.lazy there can no longer cache a failure for grid. The face-at-mount decision is unchanged, so a mount after load still renders the body directly. Ablations: both files at base → 2 failed; face only → 2 failed; index.tsx only → the form-field pin red.
  4. Gates. 44 success, 13 expected skip, 0 failed, 0 pending at this head (Test UI included); dev's 39 derived gates with 0 NOT MEASURED, packages/fields 323 files and type-check under the lock. Head is 11 behind main, none of it in ui/packages/fields.
  5. Accepted deviations. Pins sit in GridField.test.tsx inside the existing lazy-face block, as the card asked. Whether a browser re-fetches a module whose earlier import() failed is engine behaviour, not measured here (jsdom only); noted in the PR.
  6. Out of scope. The same cached-rejection edge in the other lazy faces (date, date-time and rich-text editors, markdown display, filter condition, image cropper, the per-type cache in index.tsx) is filed by the seat as Lazy field widgets remember a failed first chunk load and never recover without a page reload (date/datetime/rich text editors, rich text display, filter condition cell, image crop, getLazyFieldWidget cache) #36608 with this PR's fix shape.

Landing: area lands it (non-governed, under 3000 lines): ready + auto-merge.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 23, 2026 02:58
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 52971ff Nov 23, 2026
58 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-36451-grid-field-lazy-retry branch November 23, 2026 03:19
247257110 pushed a commit to 247257110/objectstack that referenced this pull request Nov 23, 2026
…l as null, reads names once per object, mutes an empty list (objectstack-ai#36616)

Fixes objectstack-ai#36552
Clause-②: no
Metadata-protocol: none

## 维护者速读
-
编辑带明细行表格的记录时(控制台里人员列、多选查找列),清空多选查找格现在存为空值而不是空列表;二十行的人员列从二十次读取变成一次;列表模式下空列表的破折号变灰。
- 属于明细行表格(多选、标签、人员单元格)那一批工作的收尾,替上次评审留下的四个非阻塞项收口。
- 若出错,碰到的是明细行表格里人员和查找列的名字显示或清空后的存值;改动只在表格组件内,可直接撤回这一个合并。
- 无。

Opened for `repo:objectstack#2 · os-steve ·
session_01ADHkmNmMEXS4EzeVz9RjvD` (area s2-A).

## What changes

The editable line-item grid (`@object-ui/fields`, `GridFieldWidget`),
the four items of objectstack-ai#36552:

1. **An emptied multi-record lookup cell writes `null`.** The lookup
cell's `onChange` now goes through `emptyListAsNull`, the helper the
multi-select, tags and people cells already use. Measured on
`origin/main` at `e7399fcdb` before the change: un-picking the last
record of a `lookup` column with `multiple: true` wrote
`[{"products":[]}]`.
2. **Names are read once per referenced object, not once per line.**
Measured on `origin/main` at `e7399fcdb`: twenty lines with a `user`
column and a `lookup` column (naming two products) made **20 `findOne`
on `sys_user` and 20 on `product`**, 0 `find`. Each cell is its own
`LookupField`, whose hydration reads its one bare id with `findOne`.
The grid now hands every people and lookup cell it draws (editable cell,
the people cell's resting face and panel, the read-only table, list
mode) a data source from the new `grid-field/lineReferenceReads.ts`: the
page's source, with the plain by-id read (`findOne(object, id)`, no
options) gathered per tick into one `find(object, { $filter: { id: {
$in: ids } } })` per object, ids de-duplicated, at most 50 ids per read
(`LookupField`'s own `$in` page size). Every other member, and a by-id
read carrying options, passes to the page's source unchanged (bound to
it). Same grid after the change: **1 `$in` read of `sys_user` (20 ids),
1 of `product` (2 ids), 0 `findOne`**, in editable, read-only and list
mode.
**Why not `$expand` on the child read (Prime Directive 5, SQL first):**
the grid does not make that read. Its rows arrive as a value: from
`MasterDetailForm`'s and `LineItemsPanel`'s reads of the child object
(both in `@object-ui/plugin-form`, outside this card's file surface), or
stored inline as the `grid` field's JSON, where no `$expand` reaches the
ids inside. An expanded reference in a row is also what the save diff
and the blank-line check would read and send back. One `$in` read per
object is one SQL `IN` query, at the one place every host's rows pass
through.
3. **The multi-person cell's `null` on Clear is pinned** (it was right
by reading).
4. **Display leftovers.** `cellDisplayText`'s `multiselect` arm loses
its unreachable empty-list return (the guard at the top already answers
an empty list with the em dash). In list mode the muted class reads
`isEmptyCell`, so a stored `[]` draws the em dash muted, as `null` and
`''` did.

Changeset: `.changeset/36552-line-item-grid-followups.md`, patch for
`@object-ui/fields`.

### Read first (by risk)

1. `ui/packages/fields/src/widgets/grid-field/lineReferenceReads.ts`:
the `Proxy` around the page data source, and `flush` (chunking,
de-duplication, rows keyed by `id` else `_id` as `LookupField`'s own
`$in` read keys them, `null` for an id the read did not return,
rejection fan-out).
2. `ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx`: the
`cellSource` line and the `dataSource={cellSource}` props on the five
cell sites; the lookup `onChange` hunk.
3. `ui/packages/fields/src/widgets/GridField.test.tsx`: the pins, one
top-level describe at the end of the file (`line-item grid follow-ups:
... (objectstack#36552)`).

## Tests

Seven pins in one top-level describe at the end of `GridField.test.tsx`
(moved there from a separate file once objectstack-ai#36607 landed, per ruling record
6583487846; names and assertions unchanged): multi-record lookup un-pick
writes `null`; multi-person Clear writes `null`; one `$in` read per
object and zero `findOne` with all 20 names drawn, in editable,
read-only and list mode; a backend answering with `_id` only still draws
each name from the one read; list-mode `[]` multi-select and tags cells
draw the muted em dash.

<details><summary>Package runs at head fbdfc7d (after merging
origin/main at ed0edb1, which brought objectstack-ai#36607)</summary>

- `pnpm --filter @object-ui/fields type-check` (`tsc --noEmit && tsc -p
tsconfig.test.json`): clean.
- `GridField.test.tsx` + `GridField.lookupAutofill-28245.test.tsx`:
`Test Files 2 passed (2)`, `Tests 140 passed (140)`; the seven pins
alone (`-t 36552`): `Tests 7 passed`.
- Earlier, at 2431b1b, the whole package: `Test Files 323 passed | 1
skipped (324)`, `Tests 4897 passed | 7 skipped (4904)`.
</details>

<details><summary>Ablation (one leg per pinned behaviour, through
scripts/ablation-replace.mjs, restored and proven)</summary>

The subject is imported by relative path from source, so no `dist/` is
involved. Each leg: anchor x1 to x0, blob changed, run, restore with
blob == HEAD and `git diff HEAD` empty.

- lookup `onChange` without `emptyListAsNull`: the multi-record lookup
pin fails, 1 failed / 5 passed.
- people `onWrite` without `emptyListAsNull`: the multi-person pin
fails, 1 failed / 5 passed.
- `cellSource` forced to `undefined` (cells read the page source
directly): the three one-read pins fail, 3 failed / 3 passed.
- list-mode muted test back to `null`/`''`: the muted pin fails, 1
failed / 5 passed.
- (at fbdfc7d) rows keyed by `id` only: `× a backend that answers with
_id only`, 1 failed / 6 passed.

The first four legs ran while the pins were in their own file; the moved
pins are byte-identical in name and assertion.
</details>

## Acceptance notes

- **Test placement.** The pins first lived in their own file because
open PR objectstack-ai#36607 edited `GridField.test.tsx`; objectstack-ai#36607 has merged, so they
now sit in `GridField.test.tsx` as one top-level describe (ruling record
6583487846), and the separate file is deleted.
- **Reads that still go per cell.** A by-id read with options, a lookup
column whose `idField` is not `id` (`LookupField` reads those with
`find` on an equality filter, not `findOne`), and an id the batched read
did not return (deleted or unreadable; the cell's own read gets the same
answer). Out of the card's shape; noted, not changed.
- **README / docs.** No sentence in `ui/packages/fields/README.md` or
`content/docs/frontend/` describes the per-line read, the stored `[]` or
the muted class, so none was made false; none edited.
- **Seen while measuring, not changed:** a `lookup` column with
`multiple: true` reads `undefined` in read-only and list mode (the two
read-only `LookupField` sites pass no `multiple`), while the editable
cell reads `2 selected`. Reported to the seat.

## Verification

Two minutes: from `ui/`, run `pnpm --filter @object-ui/fields exec
vitest run --root ../.. -t 36552
packages/fields/src/widgets/GridField.test.tsx`. Expect `Tests 7
passed`, the rest of the file skipped.

Gates: `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 38 families at 2b1bd44 and the
same 38 at fbdfc7d; all 38 ran locally with exit 0 at each head
(`--ran` reconciliation: 38 derived, 38 run, 0 NOT-MEASURED, all with
exit codes). Everything else is CI's.

---

_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD)_

<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmNmMEXS4EzeVz9RjvD -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fields: a failed first load of the lazy line-item grid chunk never recovers without a reload

2 participants